package xyz.xgqn.media;

import android.content.Context;
import android.util.AttributeSet;
import android.view.Surface;
import android.view.SurfaceHolder;
import android.view.SurfaceView;

public class XPlayer extends SurfaceView implements Runnable, SurfaceHolder.Callback {

    static {
        System.loadLibrary("media_jni");
    }

    public XPlayer(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    private void init() {
        getHolder().addCallback(this);
    }

    @Override
    public void surfaceCreated(SurfaceHolder surfaceHolder) {
        new Thread(this).start();
    }

    @Override
    public void surfaceChanged(SurfaceHolder surfaceHolder, int i, int i1, int i2) {

    }

    @Override
    public void surfaceDestroyed(SurfaceHolder surfaceHolder) {

    }

    @Override
    public void run() {
        xOpen("/sdcard/test.flv", getHolder().getSurface());
//        xOpenWithOpenGLES("/sdcard/test.yuv", getHolder().getSurface());
    }

    private native void xOpen(String url, Surface surface);

    private native void xOpenWithOpenGLES(String url, Surface surface);
}
